package com.cqh.recruit.result;




public class Result<T> {

    //返回的状态码
    private Integer code;

    //返回的提示信息
    private String msg;

    //返回的数据
    private T data;

    //总记录数
    private Long count;

    public Result() {
    }

    public Result(Integer code, String msg, T data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }


    /**
     * 构建分页成功返回
     * @param data
     * @param count
     * @return
     */
    public static Result buildSuccess(Object data,Long count){
        Result result=new Result();
        result.setCode(0);
        result.setData(data);
        result.setCount(count);
        result.setMsg("操作成功!");
        return result;
    }

    /**
     * 构建普通数据返回的结果
     * @param data
     * @return
     */
    public static Result buildSuccess(Object data){
        return buildSuccess(data,null);
    }

    /**
     * 构建不带返回数据的成功
     * @return
     */
    public static Result buildSuccess(){
        return buildSuccess(null);
    }

    /**
     * 构建失败的结果
     * @param code  状态码 :40001返回失败
     * @param msg   提示信息
     * @return
     */
    public static Result buildFail(Integer code,String msg){
        Result result=new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    /**
     * 获取
     * @return code
     */
    public Integer getCode() {
        return code;
    }

    /**
     * 设置
     * @param code
     */
    public void setCode(Integer code) {
        this.code = code;
    }

    /**
     * 获取
     * @return msg
     */
    public String getMsg() {
        return msg;
    }

    /**
     * 设置
     * @param msg
     */
    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 获取
     * @return data
     */
    public T getData() {
        return data;
    }

    /**
     * 设置
     * @param data
     */
    public void setData(T data) {
        this.data = data;
    }

    /**
     * 获取
     * @return count
     */
    public Long getCount() {
        return count;
    }

    /**
     * 设置
     * @param count
     */
    public void setCount(Long count) {
        this.count = count;
    }

    public String toString() {
        return "Result{code = " + code + ", msg = " + msg + ", data = " + data + ", count = " + count + "}";
    }
}

